package org.open.cobertura.core.analyzer;

import org.open.cobertura.data.CoberturaCoverageCounter;
import org.open.cobertura.data.ICoberturaLineCovered;

import java.util.Objects;

/**
 * 获取行覆盖率的接口
 */
public class CoberturaLineCoveredImpl implements ICoberturaLineCovered {

    private CoberturaCoverageCounter instructionCounter;
    private CoberturaCoverageCounter branchCounter;
    private int lineNumber;
    private int offset;

    /**
     * 创建行覆盖率
     * @param instructionCounter
     * @param branchCounter
     * @param lineNumber
     * @param offset
     */
    public CoberturaLineCoveredImpl(CoberturaCoverageCounter instructionCounter, CoberturaCoverageCounter branchCounter, int lineNumber, int offset) {
        this.instructionCounter = instructionCounter;
        this.branchCounter = branchCounter;
        this.lineNumber=lineNumber;
        this.offset=offset;
    }

    @Override
    public CoberturaCoverageCounter getInstructionCounter() {
        return this.instructionCounter;
    }

    @Override
    public CoberturaCoverageCounter getBranchCounter() {
        return this.branchCounter;
    }

    @Override
    public int getOffset() {
        return this.offset;
    }


    @Override
    public int getLineNumber() {
        return this.lineNumber;
    }



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CoberturaLineCoveredImpl that = (CoberturaLineCoveredImpl) o;
        return lineNumber == that.lineNumber;
    }

    @Override
    public int hashCode() {
        return Objects.hash(lineNumber);
    }
}
